package com.xiangge.demo;


public class OOPDemo5 {
    static class TestDemo {
        String name;
        int age;

        public void show(){
            System.out.println(name+age);
        }
        public TestDemo(String name, int age) {
            this.name = name;
            this.age = age;
        }

        // 重写toString方法
        @Override
        public String toString() {
            return "TestDemo[name:" + name + " age:" + age + "]";
        }
    }

    public static class ToStringDemo {
        public static void main(String[] args) {
            TestDemo demo = new TestDemo("小明", 18);
            // 输出：TestDemo[name:小明 age:18]
            System.out.println(demo);
        }
    }

}